﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.Model;
using ZF.BLL;
using GCELibrary.Current;
using ZF.BLL.Linq;
using ZF.DAL;
using System.Web.UI.HtmlControls;
namespace ZF.WS.UserControls
{
    public partial class HouseReqInfo : System.Web.UI.UserControl
    {
    
        public H_Qiuzu House { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
             
        }
        protected override void OnPreRender(EventArgs e)
        {
            var dt = House.DealType.ToString();
            if (dt == "0")
            {
                throw new Exception();
            }
            foreach (Control c in this.Controls)
            {
                if (c is HtmlControl)
                {
                    var hc = (HtmlControl)c;
                    if (!string.IsNullOrEmpty(hc.Attributes["key"]))
                    {
                        hc.Visible = hc.Attributes["key"].Split(',').Contains(dt);
                    }
                }
            }

         

            base.OnPreRender(e);
        }
        public string City
        {
            get
            {
                return DictionaryConfig.HArea.DefaultIfEmpty(p => p.AreaId == House.AreaId1,
                    new Dic_Area() { Name = "其他" }).Name;
            }
        }
        public string Area
        {
            get
            {
                string area = DictionaryConfig.HArea.DefaultIfEmpty(p => p.AreaId == House.AreaId1,
                    new Dic_Area() { Name = "" }).Name;
                if (!string.IsNullOrEmpty(area))
                {
                    return string.Format("[{0}]", area);
                }
                return "";
            }
        }
        public string HouseModel
        {
            get
            {
                return string.Format("{0}房{1}厅{2}阳{3}厨{4}卫", House.HX_Fan, House.HX_Tin, House.HX_Yan, House.HX_Chu, House.HX_Wei);
            }
        }
        public string BaseFacility {
            get
            {
                var ids = House.BaseFacility.Split(new string[] { "," },
                     StringSplitOptions.RemoveEmptyEntries).Select(p => p.Convert<int>()).ToArray();
                return DictionaryConfig.HBaseFacility.Where(p => ids.Contains(p.Key)).Select(p => p.Text).ConstituteString();
            }
        }
        public string WithFacility
        {
            get
            {
                var ids = House.WithFacility.Split(new string[]{","},
                     StringSplitOptions.RemoveEmptyEntries).Select(p => p.Convert<int>()).ToArray();
                return DictionaryConfig.HWithFacility.Where(p => ids.Contains(p.Key)).Select(p => p.Text).ConstituteString();
            }
        }
        public string Type
        {
            get
            {
                return SiteInfo.Instance.GetHouseTitle(House.DealType);
            }
        }
    }
}